package com.study.web.controller.basics;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.study.app.domain.vo.AppUserAgreementVo;
import com.study.app.service.IAppUserAgreementService;
import com.study.common.core.controller.AppBaseController;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;

/**
 * App用户基础信息 -- 用户 -- 隐私
 *
 * @author magicyo
 * @date 2023-04-19
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/agreement")
public class AppUserAgreementController extends AppBaseController {

    private final IAppUserAgreementService iAppUserAgreementService;

    /**
     * 不带Token获取用户条款或隐私条款
     *
     * @param type        1是隐私条款，2用户条款
     * @param displayMode 环境模式，1白天, 2黑夜
     * @return
     */
    @SaIgnore
    @GetMapping(value = "/getInfo", produces = "application/json;charset=utf-8")
    public ModelAndView getInfo(@Valid Integer type, @Valid Integer displayMode) {

        ModelAndView view = new ModelAndView();

        // 获取最新协议
        AppUserAgreementVo latestInformation = iAppUserAgreementService.getLatestInformation(type);

        if (displayMode != null && displayMode == 2) {
            view.addObject("displayMode", 2);
        } else {
            view.addObject("displayMode", 1);
        }
        view.addObject("data", latestInformation);
        view.setViewName("replace");

        return view;

    }


    /**
     * 带Token获取用户条款或隐私条款
     *
     * @param type        1是隐私条款，2用户条款
     * @param displayMode 环境模式，1白天, 2黑夜
     * @returnR
     */
    @SaCheckLogin
    @GetMapping(value = "/getInformation", produces = "application/json;charset=utf-8")
    public ModelAndView getInformation(@Valid Integer type,  @Valid Integer displayMode) {

        ModelAndView view = new ModelAndView();

        // 获取最新协议
        AppUserAgreementVo latestInformation = iAppUserAgreementService.getLatestInformation(type);

        if (displayMode != null && displayMode == 2) {
            view.addObject("displayMode", 2);
        } else {
            view.addObject("displayMode", 1);
        }
        view.addObject("data", latestInformation);
        view.setViewName("replace");

        return view;

    }

}
